/* h_prek_substitution.do ******************************************************

This file runs regressions showing substitution patterns from other PreK providers
to BPS, like Head Start and Private Schools

********************************************************************************/

* load in data
insheet using "$raw_data/MA DESE Website Scrapes/Compiled PreK Enrollment Counts/enrollment_counts_raw.csv", clear

* Initialize matrix
matrix results = J(3, 8, .)
matrix rownames results = b se N
matrix colnames results = HS HS_log priv priv_log HS_dese HS_log_dese priv_dese priv_log_dese

* Create public school enrollment variable that uses values from Figure 1 pre-2012, and DESE enrollment counts thereafter
gen public = public_paper
replace public = public_dese if year >= 2012

local types public public_dese private head_start

* Create shares
foreach t of local types {
	gen `t'_prop = (`t' / census)
	gen ln_`t'_prop = log(`t'_prop)
}

* Restrict based on years 1998-1999 to 2017-2018
reg public_prop private_prop head_start_prop year if year >= 1998 & year <= 2017

* Restrict based on years 1998-1999 to 2004-2005
reg public_prop private_prop head_start_prop year if year >= 1998 & year <= 2004

* Use hybrid public shares version
	* Regress HS on public
	reg head_start_prop public_prop
	matrix results[1, 1] = _b[public_prop]
	matrix results[2, 1] = _se[public_prop]
	matrix results[3, 1] = e(N)

	reg ln_head_start_prop ln_public_prop
	matrix results[1, 2] = _b[ln_public_prop]
	matrix results[2, 2] = _se[ln_public_prop]
	matrix results[3, 2] = e(N)

	* Regress private on public
	reg private_prop public_prop
	matrix results[1, 3] = _b[public_prop]
	matrix results[2, 3] = _se[public_prop]
	matrix results[3, 3] = e(N)

	reg ln_private_prop ln_public_prop
	matrix results[1, 4] = _b[ln_public_prop]
	matrix results[2, 4] = _se[ln_public_prop]
	matrix results[3, 4] = e(N)

* Use DESE data only for public shares
	* Regress HS on public
	reg head_start_prop public_dese_prop
	matrix results[1, 5] = _b[public_dese_prop]
	matrix results[2, 5] = _se[public_dese_prop]
	matrix results[3, 5] = e(N)

	reg ln_head_start_prop ln_public_dese_prop
	matrix results[1, 6] = _b[ln_public_dese_prop]
	matrix results[2, 6] = _se[ln_public_dese_prop]
	matrix results[3, 6] = e(N)

	* Regress private on public
	reg private_prop public_dese_prop
	matrix results[1, 7] = _b[public_dese_prop]
	matrix results[2, 7] = _se[public_dese_prop]
	matrix results[3, 7] = e(N)

	reg ln_private_prop ln_public_dese_prop
	matrix results[1, 8] = _b[ln_public_dese_prop]
	matrix results[2, 8] = _se[ln_public_dese_prop]
	matrix results[3, 8] = e(N)


* Export to Excel file
matrix list results

* Output to Excel
putexcel set "$results/raw_tabs/Table_A3.xlsx", sheet("subst reg coeffs") modify
putexcel A1 = matrix(results), names
